﻿using ChatWithMe.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace ChatWithMe.ViewModels
{
     public  class LoginViewModel : BindableBase
    {

        private string _avatar;

        public string Avatar
        {
            get { return _avatar; }
            set { SetProperty(ref _avatar, value); }
        }
        private string _userName;

        public string UserName
        {
            get { return _userName; }
            set { _userName = value;
                //当用户名发生变化时要调用  通知登陆判断逻辑
                LoginComman.OnCanexecuteChanged();
            }
        }
        private string _password;

        public string Password
        {
            get { return _password; }
            set { _password = value;
                //当用户名发生变化时要调用  通知登陆判断逻辑
                LoginComman.OnCanexecuteChanged();
            }
        }



        public Command LoginComman { get; set; }
        public Command AboutComman { get; set; }
        public Command ExitComman { get; set; }



         public LoginViewModel ()
    {

        LoginComman = new Command(p=> {
            //导航到新页面
            var rootFrame = Window.Current.Content as Frame;
            rootFrame.Navigate(typeof(MainPage));
        },p=> {
            //TODO:登陆逻辑 

            var viewModel = p as LoginViewModel;//as强转
            if (viewModel == null) return false;
            return !string.IsNullOrEmpty(viewModel.UserName)&& !string.IsNullOrEmpty(viewModel.Password);
        });

            AboutComman = new Command(async p =>
            {
                //打开网页   或转到应用商店的App名字
                await Launcher.LaunchUriAsync(new Uri("http://www.cnblogs.com/rongweijun/"));
                //await Launcher.LaunchUriAsync(new Uri("ms-windows-store:reviewapp?appid=" + CurrentApp.AppID));

            });
            //退出应用
            ExitComman = new Command(p=> { App.Current.Exit(); });


#if DEBUG
                    Avatar="ms-appx:///Assets/avator/未标题-1.png";
#endif 
        }

    }

}
